/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import java.io.Serializable;
import javax.annotation.Nullable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author damfercer
 */
@Entity
@Table(name = "candidate_educational_info")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "CandidateEducationalInfo.findAll", query = "SELECT c FROM CandidateEducationalInfo c"),
    @NamedQuery(name = "CandidateEducationalInfo.findByIdCandidateEducationalInfo", query = "SELECT c FROM CandidateEducationalInfo c WHERE c.idCandidateEducationalInfo = :idCandidateEducationalInfo"),
    @NamedQuery(name = "CandidateEducationalInfo.findByDescription", query = "SELECT c FROM CandidateEducationalInfo c WHERE c.description = :description")})
public class CandidateEducationalInfo implements Serializable {
    @JoinColumn(name = "STATUS", referencedColumnName = "ID_EDUCATIONAL_STATUS")
    @ManyToOne(optional = false)
    @Nullable
    private EducationalStatus status;
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID_CANDIDATE_EDUCATIONAL_INFO")
    private Integer idCandidateEducationalInfo;
    @Size(max = 100)
    @Column(name = "DESCRIPTION")
    private String description;
    @JoinColumn(name = "EDUCATIONAL_LEVEL", referencedColumnName = "ID_EDUCATIONAL_LEVEL")
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private EducationalLevel educationalLevel;
    @JoinColumn(name = "CANDIDATE", referencedColumnName = "ID_CANDIDATE")
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Candidate candidate;
    @JoinColumn(name = "SECTOR", referencedColumnName = "ID_SECTOR")
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Sector sector;

    public CandidateEducationalInfo() {
    }

    public CandidateEducationalInfo(Integer idCandidateEducationalInfo) {
        this.idCandidateEducationalInfo = idCandidateEducationalInfo;
    }

    public Integer getIdCandidateEducationalInfo() {
        return idCandidateEducationalInfo;
    }

    public void setIdCandidateEducationalInfo(Integer idCandidateEducationalInfo) {
        this.idCandidateEducationalInfo = idCandidateEducationalInfo;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public EducationalLevel getEducationalLevel() {
        return educationalLevel;
    }

    public void setEducationalLevel(EducationalLevel educationalLevel) {
        this.educationalLevel = educationalLevel;
    }

    public Candidate getCandidate() {
        return candidate;
    }

    public void setCandidate(Candidate candidate) {
        this.candidate = candidate;
    }

    public Sector getSector() {
        return sector;
    }

    public void setSector(Sector sector) {
        this.sector = sector;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idCandidateEducationalInfo != null ? idCandidateEducationalInfo.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        boolean res=false;
        if (object instanceof CandidateEducationalInfo) {
            CandidateEducationalInfo other = (CandidateEducationalInfo) object;
            if(this.idCandidateEducationalInfo!=null && other.getIdCandidateEducationalInfo()!=null){
                res=this.idCandidateEducationalInfo.equals(other.getIdCandidateEducationalInfo());
            }
            else{
                if(this.getSector()!=null && other.getSector()!=null){
                    if(this.getDescription()!=null && other.getDescription()!=null){
                        res=(this.getEducationalLevel().getIdEducationalLevel().equals(other.getEducationalLevel().getIdEducationalLevel())) && this.getSector().getIdSector().equals(other.getSector().getIdSector()) && this.getDescription().equalsIgnoreCase(other.getDescription());
                    }
                    else{
                        res= (this.getEducationalLevel().getIdEducationalLevel().equals(other.getEducationalLevel().getIdEducationalLevel())) && this.getSector().getIdSector().equals(other.getSector().getIdSector());                        
                    }
                }
                else{
                    res= this.getEducationalLevel().getIdEducationalLevel().equals(other.getEducationalLevel().getIdEducationalLevel());
                }       
            }     
        }
        return res;
    }

    @Override
    public String toString() {
        return "entities.CandidateEducationalInfo[ idCandidateEducationalInfo=" + idCandidateEducationalInfo + " ]";
    }

    public EducationalStatus getStatus() {
        return status;
    }

    public void setStatus(EducationalStatus status) {
        this.status = status;
    }
    
}
